const mongoose = require('mongoose')

const schema = new mongoose.Schema({
    account_id: { type: String },
    password: {
        type: String,
        select: false,   //默认不取出
        set(val) {
            return require('bcryptjs').hashSync(val, 10)
          }              //密码加密
      },
      wx_name: { type: String },
      openid: { type: String },
      token: { type: String },
      default_address:[{
        area:{type:String},
        service:{type:String},
        local:{type:String},
        name:{type:String}
      }],
      address: [{ 
        name: { type: String },
      phone: { type: String },
      local: { type: String },
      number: { type: String }
    }],
      shopping_cart: [{ 
        goods: { type: mongoose.SchemaTypes.ObjectId, ref: 'Goodslist' },
        value: Number
    }],
    orders: [{ type: mongoose.SchemaTypes.ObjectId, ref: 'Order' }],
    status:{ type: String, default: "1" }
})

module.exports = mongoose.model('Customer', schema)